package com.caigou.comm.base.widget

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.view.Gravity
import android.view.View
import android.view.Window
import android.view.WindowManager
import android.widget.TextView
import com.caigou.comm.R

/**
 * @author #Suyghur.
 * Created on 2021/11/17
 */
class TipsDialog(context: Context, doubleButton: Boolean = false) : Dialog(context) {

    lateinit var tvTitle: TextView
    lateinit var tvContent: TextView
    lateinit var tvLeft: TextView
    lateinit var tvRight: TextView

    init {
        setCanceledOnTouchOutside(true)
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        initView(doubleButton)
    }

    private fun initView(doubleButton: Boolean) {
        setContentView(R.layout.comm_tips_dialog)

        val attr = window?.attributes as WindowManager.LayoutParams
        //设置dialog在布局中的位置
        attr.gravity = Gravity.CENTER

        tvTitle = findViewById(R.id.tips_dialog_tv_title)
        tvContent = findViewById(R.id.tips_dialog_tv_content)
        tvLeft = findViewById(R.id.tips_dialog_tv_left)
        tvRight = findViewById(R.id.tips_dialog_tv_right)
        val view = findViewById<View>(R.id.tips_dialog_v)

        if (!doubleButton) {
            view.visibility = View.GONE
            tvLeft.visibility = View.GONE
        }

    }
}